package com.online.usermanagesystem.dao;

import com.online.usermanagesystem.entity.Company;
import com.online.usermanagesystem.utils.UpdateLangDriver;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author jhk
 */

@Mapper
public interface CompanyMapper {

    @Select("select name,code,telephone,address from ols_company where id=#{id}")
    Company query(Integer id);

    @Select("select count(*) from ols_company where id=#{id}")
    Integer countById(Integer id);

    @Select("select count(*) from ols_company where name=#{name}")
    Integer countByName(String name);

    @Insert("insert into ols_company(name,code,telephone,address,time_create,config) values(#{name},#{code},#{telephone},#{address},now(),'{}')")
    @Options(useGeneratedKeys = true)
    Integer insert(Company company);

    //@Update("update ols_company set name=#{name},code=#{code},telephone=#(telephone),address=#{address}) where id=#{id})")
    @Update("update ols_company(#{company}) WHERE id = #{id}")
    @Lang(UpdateLangDriver.class)
    Integer update(Company company);

    @Delete("delete from ols_company where id=#{id}")
    Integer delete(Integer id);

    @Select("select A.id,name,code,telephone,address from ols_company as A,(select id from ols_company limit #{index},#{count}) as B where A.id=B.id")
    List<Company> querys(@Param(value = "index") Integer index, @Param(value = "count") Integer count);

    @Select("select A.id,name,code,telephone,address from ols_company as A,(select id from ols_company where name like #{keyword} limit #{index},#{count}) as B where A.id=B.id")
    List<Company> search(@Param(value = "keyword") String keyword, @Param(value = "index") Integer index, @Param(value = "count") Integer count);
}
